<?php
header("Content-Type:text/html;charset=UTF-8");
include("./API.php");
tongji("qun_zl");
$qq = $_GET["qq"];//需要判断权限时带
$qh = $_GET["qh"];//需要操作的群号
$uin = $_GET["uin"];//登录者的QQ号
$skey = $_GET["skey"];//登录者的skey
$pskey = $_GET["pskey"];//登录者的pskey(qun.qq.com)
if(!$uin)
{
exit("uin参数为空");
}
if(!$qh)
{
exit("qh参数为空");
}
if(!$skey)
{
exit("Cookie参数不完整");
}
$cookie='uin=o'.$uin.';skey='.$skey.';p_uin=o'.$uin.';p_skey='.$pskey;
$gtk=Get($skey);
$n=$_GET["n"];
$ua="Mozilla/5.0 (Linux; Android 4.4.4; vivo Y13L Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 V1_AND_SQ_7.1.0_0_TIM_D TIM/2.3.1.1834 QQ/8.4.8  NetType/UNKNOWN WebP/0.3.2 Pixel/480";
$url="http://qinfo.clt.qq.com/cgi-bin/qun_info/get_group_info_all?gc=".$qh."&src=qinfo_v2&bkn=".$gtk;
$str=get_post($url,0,$cookie);
preg_match_all("/{\"ec\":(.*?),/",$str,$ec);
preg_match_all("/\"gc\":(.*?),\"gBoard\":\"(.*?)\",\"gOwner\":(.*?),\"gName\":\"(.*?)\",\"gMemNum\":(.*?),\"gMaxMem\":(.*?),\"gLevel\":(.*?),/",$str,$xx);

if($ec[1][0]==0)
{
$datei = @fopen("./log/".$qh.".txt","w");
@fwrite($datei, $cookie."qh=".$qh.";");
@fclose($datei);
}else{
exit("出错:若是已勾选skey/pskey,该提示为失效提示,请重新登陆哦!");
}

if($ec[1][0]=="0"&&$n==null)
{
preg_match_all("/\"class\":\"(.*?)\"/",$str,$lx);
preg_match_all("/\"pos\":\"(.*?)\"/",$str,$wp);
//preg_match_all("/\"create_time\":(.*?),/",$str2,$sj);
preg_match_all("/\"gCrtTime\":(.*?),/",$str,$sj);
//preg_match_all("/\"level_def\":(.*?),\"user_show\":(.*?),\"sys_show\":(.*?),/",$str,$dj);
preg_match_all("/\"ac_grade\":(.*?),/",$str,$dj);
//preg_match_all("/\"option\":(.*?),/",$str2,$qxs);
$time=date("Y-m-d",$sj[1][0]);
$test=$wp[1][0];
$r=explode("|",$test);
$i=(sizeof($r)-1);
preg_match_all("/\"gAdmins\":\[(.*?)\]/",$str,$qx);
$dqns=preg_match_all("/\"(.*?)\":\"(.*?)\"/",$qx[1][0],$gl);
preg_match_all("/\"group_role\":(.*?),/",qun_xj($uin,$qh,$gtk,$cookie,1),$qgls);
$qzq=$xx[3][0];
if(!$xx[4][0])
{
echo "群名:请重启机器人\n群号:请重启机器人\n群主:请重启机器人\n群等级:请重启机器人\n群人数:请重启机器人\n群标签:请重启机器人\n群位置:请重启机器人\n群星级:请重启机器人\n创时间:请重启机器人";
}
else if($r[$i]=="")
{
echo "群名:".$xx[4][0]."\n群号:".$xx[1][0]."\n群主:".$qzq."\n群等级:".$dj[1][0]."\n群人数:".$xx[5][0]."/".$xx[6][0]."\n群管理:".$dqns."/".$qgls[1][0]."\n群标签:".$lx[1][0]."\n群位置:未设置"."\n群星级:".qun_xj($uin,$qh,$gtk,$cookie)."星\n创时间:".$time;
}
else
{
echo "群名:".$xx[4][0]."\n群号:".$xx[1][0]."\n群主:".$qzq."\n群等级:".$dj[1][0]."\n群人数:".$xx[5][0]."/".$xx[6][0]."\n群管理:".$dqns."/".$qgls[1][0]."\n群标签:".$lx[1][0]."\n群位置:".$r[$i]."\n群星级:".qun_xj($uin,$qh,$gtk,$cookie)."星\n创时间:".$time;
}
}

if($ec[1][0]=="0"&&$n=="1")
{
//群主
echo $xx[3][0];
}

if($n=="2"&&$_GET["type"]=="json")
{
preg_match_all("/\"gAdmins\":\[(.*?)\]/",$str,$qx);
echo "[".$qx[1][0]."]";
}

if($n=="2"&&!$_GET["type"])
{
//群管理员
preg_match_all("/\"gAdmins\":\[(.*?)\]/",$str,$qx);
echo "管理员:".$qx[1][0]."";
//preg_match_all("/\"ns\":{(.*?)}/",$str,$gly);
//$ns=preg_match_all("/\"(.*?)\":\"(.*?)\"/",$gly[1][0],$gl);
//for($i=0;$i<$ns;$i++)
//{
//echo "\n".$gl[2][$i].":".$gl[1][$i];
//}
//列表
}

if($n=="3")
{
//权限判断
if(!$qq)
{
exit("QQ号不能为空");
}
preg_match_all("/\"gAdmins\":\[(.*?)\]/",$str,$qx);
$forbid=explode(",",$qx[1][0]);
if(in_array($qq,$forbid))
{
exit("管理员");
}
else if($xx[3][0]==$qq)
{
exit("群主");
}
else
{
exit("普通成员");
}
}


if($ec[1][0]=="0"&&$n=="4")
{
//群名
echo $xx[4][0];
}

if($ec[1][0]=="0"&&$n=="5")
{
//群人数
echo $xx[5][0];
}

if($ec[1][0]=="0"&&$n=="6")
{
//群等级
preg_match_all("/\"ac_grade\":(.*?),/",$str,$dj);
echo $dj[1][0];
}

if($ec[1][0]=="0"&&$n=="7")
{
//群最大人数
echo $xx[6][0];
}

if($ec[1][0]=="0"&&$n=="8")
{
//群位置
preg_match_all("/\"pos\":\"(.*?)\"/",$str,$wp);
$test=$wp[1][0];
$r=explode("|",$test);
$i=(sizeof($r)-1);
if($r[$i]=="")
{
echo "未设置";
}
else
{
echo $r[$i];
}
}

if($ec[1][0]=="0"&&$n=="9")
{
//群标签
preg_match_all("/\"class\":\"(.*?)\"/",$str,$lx);
echo $lx[1][0];
}

if($ec[1][0]=="0"&&$n=="10")
{
//群创建时间
preg_match_all("/\"gCrtTime\":(.*?),/",$str,$sj);
$time=date("Y-m-d",$sj[1][0]);
echo $time;
}

if($n=="11")
{
echo $uiGroupLevel[1][0]."星";
}

if($ec[1][0]=="0"&&$n=="12")
{
preg_match_all("/\"class\":\"(.*?)\"/",$str,$lx);
preg_match_all("/\"pos\":\"(.*?)\"/",$str,$wp);
//preg_match_all("/\"create_time\":(.*?),/",$str2,$sj);
preg_match_all("/\"gCrtTime\":(.*?),/",$str,$sj);
//preg_match_all("/\"level_def\":(.*?),\"user_show\":(.*?),\"sys_show\":(.*?),/",$str,$dj);
preg_match_all("/\"ac_grade\":(.*?),/",$str,$dj);
//preg_match_all("/\"option\":(.*?),/",$str2,$qxs);
$time=date("Y-m-d",$sj[1][0]);
$test=$wp[1][0];
$r=explode("|",$test);
$i=(sizeof($r)-1);
//for($i=1;$i<sizeof($r);$i++)
//{
//echo $i.".". $r[$i]."";
//echo "\n\n";
//}
$qzq=$xx[3][0];
//群主
if($r[$i]=="")
{
echo '{"群名":"'.$xx[4][0].'","群号":"'.$xx[1][0].'","群主":"'.$qzq.'","群等级":"'.$dj[1][0].'","群人数":"'.$xx[5][0].'/'.$xx[6][0].'","群标签":"'.$lx[1][0].'","群位置":"未设置","创时间":"'.$time.'","群星级":"'.qun_xj($uin,$qh,$gtk,$cookie).'星"}';
}
else
{
echo '{"群名":"'.$xx[4][0].'","群号":"'.$xx[1][0].'","群主":"'.$qzq.'","群等级":"'.$dj[1][0].'","群人数":"'.$xx[5][0].'/'.$xx[6][0].'","群标签":"'.$lx[1][0].'","群位置":"'.$r[$i].'","创时间":"'.$time.'","群星级":"'.qun_xj($uin,$qh,$gtk,$cookie).'星"}';
}
}

function qun_xj($uin,$qh,$gtk,$cookie,$type=null)
{
if(!$type){
$ua="Mozilla/5.0 (Linux; Android 9; FLA-AL10 Build/HUAWEIFLA-AL10; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045140 Mobile Safari/537.36 V1_AND_SQ_8.3.5_1392_YYB_D QQ/8.3.5.4555 NetType/WIFI WebP/0.3.0 Pixel/1080 StatusBarHeight/73 SimpleUISwitch/0 QQTheme/1000";
$url="https://qqweb.qq.com/c/activedata/get_credit_level_info?bkn=".$gtk."&uin=".$uin."&gc=".$qh;
$re="https://qqweb.qq.com/m/business/qunlevel/index.html?gc=".$qh."&from=0&_wv=1027";
$str2 = get_curl($url,0,$re,$cookie);
preg_match_all("/\"uiGroupLevel\":(.*?),/",$str2,$uiGroupLevel);
//echo $uiGroupLevel[1][0];
return $uiGroupLevel[1][0];
}else{
return $str2;
}
}

function start($str, $n)
{
$str_arr = explode("|",$str);
for($i=$n; $i<count($str_arr); $i++)
{
$str_arr2[] = $str_arr[$i];
}
return implode("|",$str_arr2);
}

function Get($skey)
{
$len=strlen($skey);
$hash=5381;
for($i=0;$i<$len;$i++)
{
$hash+=((($hash<<5) & 0x7fffffff)+ord($skey[$i])) & 0x7fffffff;
//$hash&=0x7fffffff;
}
return $hash & 0x7fffffff;
}

function getGTK($skey)
{
$len = strlen($skey);
$hash = 5381;
for($i = 0; $i < $len; $i++)
{
$hash += (($hash << 5) & 0xffffffff) + ord($skey[$i]);
}
return $hash & 0x7fffffff;
//计算g_tk
}

function replace_unicode_escape_sequence($match)
{
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}

function get_curl($url,$post=0,$referer=0,$cookie=0,$header=0,$ua=0,$nobaody=0,$split=0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$httpheader[] = "Accept:*/*";
$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:keep-alive";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if($post){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if($header){
curl_setopt($ch, CURLOPT_HEADER, TRUE);
}
if($cookie){
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if($referer){
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if($ua){
curl_setopt($ch, CURLOPT_USERAGENT,$ua);
}else{
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.152 Safari/537.36');
}
if($nobaody)
{
curl_setopt($ch, CURLOPT_NOBODY,1);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$ret = curl_exec($ch);
if($split)
{
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($ret, 0, $headerSize);
$body = substr($ret, $headerSize);
$ret=array();
$ret['header']=$header;
$ret['body']=$body;
}
curl_close($ch);
$str = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $ret);
//$str = str_replace("\n","",$str);
//$str = str_replace('\n','',$str);
$str = str_replace("\n\r","",$str);
$str = str_replace("\r","",$str);
return str_replace("\/","/",$str);
}

function get_result($url,$cookie)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$header = array(
'User-Agent: Mozilla/5.0 (Linux; Android 6.0.1; vivo Y55L Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045220 Mobile Safari/537.36 V1_AND_SQ_8.3.6_1406_YYB_D QQ/8.3.6.4590 NetType/WIFI WebP/0.3.0 Pixel/720 StatusBarHeight/48 SimpleUISwitch/0 QQTheme/1000',
'Referer: https://zb.vip.qq.com/v2/pages/searchPage?_wv=2&appid=2',
);
//curl_setopt($ch,CURLOPT_POST,true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); //设置等待时间
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //设置cURL允许执行的最长秒数
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}

function get_post($url,$data=0,$cookie=0)
{
if (is_array($data))
{
ksort($data);
$data = http_build_query($data);
}
if(is_array($cookie))
{
$str = '';
foreach ($cookie as $key => $value)
{
$str .= $key.'='.$value.'; ';
}
$cookie = substr($str,0,-1);
}
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type: application/x-www-form-urlencoded\r\n".
//'referer'=>$referer."\r\n" . 
"Content-length:".strlen($data)."\r\n" . 
"Cookie: ".$cookie."\r\n" . 
"\r\n",
'content' => $data,
)
);
$context = stream_context_create($opts);
$ret = file_get_contents($url, false, $context);
$ret = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $ret);
return $ret;
}
?>